package com.example.cas;

import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.ToString;
import lombok.extern.slf4j.Slf4j;

import java.util.concurrent.atomic.AtomicReference;


@Slf4j
public class AtomicReferenceDemo {
    public static void main(String[] args) {
        User z3 = new User("z3", 24);
        User li4 = new User("li4", 26);

        AtomicReference<User> atomicReferenceUser = new AtomicReference<>();

        atomicReferenceUser.set(z3);
        log.info("ret:{},{}", atomicReferenceUser.compareAndSet(z3, li4), atomicReferenceUser.get());
        log.info("ret:{},{}", atomicReferenceUser.compareAndSet(z3, li4), atomicReferenceUser.get());
    }
}

@Getter
@ToString
@AllArgsConstructor
class User {
    String userName;
    int age;
}